import Cookies from 'js-cookie';
import { getBroswer } from 'utils/tool'

// export const wxLogin = () => {
//   const isWx = getBroswer().weChat;
//   if (isWx) {
//     const wx_login = Cookies.get('wx_login');
//     if (!wx_login || wx_login == 'false') {
//
//       Cookies.set('iswx', '1');
//       let appId = 'wx23c30a1a942be760';
//       let redirectUrl = window.location.href;
//       // let redirectUrl = 'http://test.wx.plus.1sight.cn/live/41755';
//       let originUrl = Cookies.get('originUrl');
//       if (!originUrl) {
//         Cookies.set('originUrl', redirectUrl);
//         redirectUrl = encodeURIComponent(redirectUrl);
//         window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect=`
//       } else {
//         window.location.href = originUrl;
//       }
//     } else if (wx_login == 'true') {
//       Cookies.set('iswx', '1');
//     }
//   } else {
//     Cookies.set('iswx', '0');
//   }
// }

export const wxUserInfo = () => {
  const isWx = getBroswer().weChat;
  var HOST = window.location.host
  var ACTIVITYNO = Cookies.get('activity_no')
  if (isWx) {
    const WX_INFO = Cookies.get('wx_info');
    if (!WX_INFO || (WX_INFO && WX_INFO == "0")) {
      window.location.href = '//' + HOST + '/live/' + ACTIVITYNO + '?wxStatus=noinfo'
    }
  }

}
